PUBLIC = ../../public
SRC = src
GLOBAL_BIN = ../../bin
BIN = ../../bin
CFLAGS = -Wall -pedantic -ansi -Werror
CC = gcc
LIB_TOOL = ar
LIB_FLAGS = -r -s
COMPILE_FLAG = -c

all: release 

release_app: BIN=../../bin/release
release_app: $(BIN)/FtpServer

debug_app: BIN=../../bin/debug
debug_app: $(BIN)/FtpServer


$(BIN)/FtpServer: main.o 
	$(CC) $(CFLAGS) main.o -L$(BIN) -lFtpServer -lGenericServer -lTree -lSTScheduler -lList -o $(BIN)/FtpServer

main.o: main.c $(PUBLIC)/FtpServer.h
	$(CC) $(COMPILE_FLAG) $(CFLAGS) -D_GNU_SOURCE -I$(PUBLIC) main.c -o main.o

debug: CFLAGS+=-g 
debug: BIN=../../bin/debug
debug: $(BIN)/libFtpServer.a clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		 LIBRARY CREATED			*"
	@echo "*							*"
	@echo "**********************************************************"

release: CFLAGS+=-O3 -DNDEBUG
release: BIN=../../bin/release
release: $(BIN)/libFtpServer.a clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		 LIBRARY CREATED			*"
	@echo "*							*"
	@echo "**********************************************************"

$(BIN)/libFtpServer.a: FtpServer.o 
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		CREATING LIBRARY			*"
	@echo "*							*"
	@echo "**********************************************************"
	$(LIB_TOOL) $(LIB_FLAGS) $(BIN)/libFtpServer.a FtpServer.o 

Testdebug: CFLAGS+=-g -DGS_UTEST
Testdebug: BIN=bin/debug
Testdebug: $(BIN)/FtpServerTest clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		SUCCEFULY FINISHED			*"
	@echo "*							*"
	@echo "**********************************************************"


Testrelease: CFLAGS+=-DNDEBUG -DGS_UTEST
Testrelease: BIN=bin/release
Testrelease: $(BIN)/FtpServerTest clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		SUCCEFULY FINISHED			*"
	@echo "*							*"
	@echo "**********************************************************"

$(BIN)/FtpServerTest: FtpServer.o
	$(CC) $(CFLAGS) FtpServer.o -L$(GLOBAL_BIN) -lGenericServer -lTree -o $(BIN)/FtpServerTest


FtpServer.o: $(PUBLIC)/FtpServer.h $(PUBLIC)/GenericServer.h $(PUBLIC)/Tree.h FtpServer.c
	$(CC) $(COMPILE_FLAG) $(CFLAGS) -D_GNU_SOURCE -I$(PUBLIC) FtpServer.c -o FtpServer.o


clean: 
	rm *.o
